//
//  UILabel+CreateSpaceForLine.m
//  LovingPartyBuilding
//
//  Created by 刘应平 on 2017/6/7.
//  Copyright © 2017年 刘应平. All rights reserved.
//

#import "UILabel+CreateSpaceForLine.h"

@implementation UILabel (CreateSpaceForLine)
+ (NSMutableAttributedString *)setSpaceForLineWithText:(NSString *)text lineSpace:(CGFloat)space{
    /**  设置行距  */
    NSMutableAttributedString *text2 = [[NSMutableAttributedString alloc] initWithString:text];
    
    NSMutableParagraphStyle *style2 = [[NSMutableParagraphStyle alloc] init];
    style2.headIndent = 0;
    style2.lineSpacing = space;
    [text2 addAttribute:NSParagraphStyleAttributeName value:style2 range:NSMakeRange(0, text2.length)];

    return text2;
}

/*

 (NSString*)str  内容
 withFont:(float)font 字体大小
 WithSpace:(float)space 行间距
 */
//给UILabel设置行间距和字间距
+ (NSAttributedString *)setLabelSpacewithValue:(NSString*)str withFont:(float)font WithSpace:(float)space{
    NSMutableParagraphStyle *paraStyle = [[NSMutableParagraphStyle alloc] init];
    paraStyle.lineBreakMode = NSLineBreakByCharWrapping;
    paraStyle.alignment = NSTextAlignmentLeft;
    paraStyle.lineSpacing = space; //设置行间距
    paraStyle.hyphenationFactor = 1.0;
    paraStyle.firstLineHeadIndent = 0.0;
    paraStyle.paragraphSpacingBefore = 0.0;
    paraStyle.headIndent = 0;
    paraStyle.tailIndent = 0;
    //设置字间距 NSKernAttributeName:@1.5f
    UIFont *tfont = [UIFont systemFontOfSize:font];
    NSDictionary *dic = @{NSFontAttributeName:tfont, NSParagraphStyleAttributeName:paraStyle, NSKernAttributeName:@1.5f
                          };
    NSAttributedString *attributeStr = [[NSAttributedString alloc] initWithString:str attributes:dic];
    return attributeStr;
}

@end
